package com.example.bob.dao;


import com.example.bob.model.ArticleInfo;
import com.example.bob.model.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.AbstractList;
import java.util.List;

/*@Mapper注解已经在启动类统一添加完成*/
@Mapper
public interface ArticleMapper {

    //查询某个用户的所有文章
    @Select("select * from articleinfo where uid=#{uid} order by id desc ")
    List<ArticleInfo> getListByUser(int uid);


    //查询文章表所有文章
//    @Select("select * from articleinfo order by id desc limit #{psize} offset #{pindex}")
    @Select("select * from articleinfo order by id desc limit #{psize} offset #{offset}")
    public List<ArticleInfo> getListByPage(@Param("psize") int psize, @Param("offset") int offset);

    //添加文章
    @Insert("insert into articleinfo(title,content,uid) values(#{title},#{content},#{uid})")
    int add(ArticleInfo articleInfo);

    //根据 aid删除文章
    @Delete("delete from articleinfo where id=#{id} and uid=#{uid}")
    int del(ArticleInfo articleInfo);

    //根据aid查询文章详情，返回什么呢？返回对象！因为文章详情页不止展示文章，要展示的是文章对象！

    @Select("select * from articleinfo where id=#{id}")
    ArticleInfo detail(int aid);


    @Update("update articleinfo set title=#{title},content=#{content} where id=#{id} and uid=#{uid}")
    int updata(ArticleInfo articleInfo);


    //统计文章总数量
    @Select("select count(*) from articleinfo")
    int count();

    // 查询文章访问量
    @Select("select recount from articleinfo where id=#{aid}")
    int getReCount(int aid);


//    修改文章访问量
    @Update("update articleinfo set recount=#{recount} where id = #{id}")
    void setReCount(int recount,int id);

    @Select("select count(*) from articleinfo where uid=#{uid}")
    int artCount(int uid);
}
